package com.liuwa.knowledge.controller;

import java.util.List;

import com.liuwa.common.utils.bean.BeanUtils;
import com.liuwa.common.exception.ServiceException;
import com.liuwa.common.utils.poi.ExportResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.liuwa.common.annotation.Log;
import com.liuwa.common.core.controller.BaseController;
import com.liuwa.common.enums.BusinessType;
import com.liuwa.knowledge.domain.FltrpWord;
import com.liuwa.knowledge.query.FltrpWordQuery;

import com.liuwa.knowledge.service.FltrpWordService;
import com.liuwa.common.utils.poi.ExcelUtil;
import com.liuwa.common.bean.Page;

/**
 * 外研社单词Controller
 * 
 * @author liuwa
 * @date 2025-04-02 08:48:16
 */
@RestController
@Api(value = "外研社单词")
@RequestMapping("/fltrp/words")
public class FltrpWordController extends BaseController{

    @Autowired
    private FltrpWordService fltrpWordService;

    /**
     * 查询外研社单词列表
     */
    @ApiOperation("查询外研社单词列表")
    @PreAuthorize("@ss.hasPermi('fltrp:word:list')")
    @GetMapping
    public Page<FltrpWord> list(FltrpWordQuery query)
    {
        FltrpWord condition = new FltrpWord();
        BeanUtils.copyBeanNotNull2Bean(query, condition);
        startPage(query);
        List<FltrpWord> list = fltrpWordService.findList(condition);
        return getPage(list, query);
    }


    /**
     * 导出外研社单词列表
     */
    @ApiOperation("导出外研社单词")
    @PreAuthorize("@ss.hasPermi('fltrp:word:export')")
    @Log(title = "导出外研社单词", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public ExportResult export(FltrpWordQuery query)
    {
        FltrpWord condition = new FltrpWord();
        BeanUtils.copyBeanNotNull2Bean(query, condition);
        List<FltrpWord> list = fltrpWordService.findList(condition);
        ExcelUtil<FltrpWord> util = new ExcelUtil<FltrpWord>(FltrpWord.class);
        return util.exportExcel(list, "外研社单词数据");
    }

    /**
     * 获取外研社单词详细信息
     */
    @ApiOperation("获取外研社单词详细信息")
    @PreAuthorize("@ss.hasPermi('fltrp:word:query')")
    @GetMapping(value = "/{id}")
    public FltrpWord get(@PathVariable("id") Integer id)
    {
        return fltrpWordService.get(id);
    }

    /**
     * 新增外研社单词
     */
    @ApiOperation("新增外研社单词")
    @PreAuthorize("@ss.hasPermi('fltrp:word:add')")
    @Log(title = "新增外研社单词", businessType = BusinessType.INSERT)
    @PostMapping
    public void add(@RequestBody FltrpWord fltrpWord)
    {
        fltrpWordService.insert(fltrpWord);
    }

    /**
     * 修改外研社单词
     */
    @ApiOperation("修改外研社单词")
    @PreAuthorize("@ss.hasPermi('fltrp:word:edit')")
    @Log(title = "修改外研社单词", businessType = BusinessType.UPDATE)
    @PutMapping
    public void edit(@RequestBody FltrpWord fltrpWord)
    {
        FltrpWord oldFltrpWord = fltrpWordService.get(fltrpWord.getId());
        if(oldFltrpWord == null){
            throw new ServiceException("操作的外研社单词不存在或已删除");
        }
        BeanUtils.copyBeanNotNull2Bean(fltrpWord, oldFltrpWord);
        fltrpWordService.update(oldFltrpWord);
    }



    /**
     * 删除外研社单词
     */
    @ApiOperation("删除外研社单词")
    @PreAuthorize("@ss.hasPermi('fltrp:word:remove')")
    @Log(title = "删除外研社单词", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public void remove(@PathVariable Integer[] ids)
    {
		fltrpWordService.batchDelete(ids);
    }
	
	
}
